import React from 'react'
import store from '../store'
import { bindActionCreators } from '../my-redux'
import actionCreators from '../store/actionCreators/counter1'



const boundActions = bindActionCreators(actionCreators,store.dispatch) 
class Counter1 extends React.Component {
    state = { number: store.getState().counter1.number }
    componentDidMount() {
        this.unsubscribe = store.subscribe(() => {
            this.setState({
                number: store.getState().counter1.number
            })
        })
    }
    componentWillUnmount() {
        this.unsubscribe()
    }
    render() {
        return (<div>
            <p>{this.state.number}</p>
            <button onClick={ boundActions.add1}>+</button>
            <button onClick={ boundActions.minus1}>-</button>
        </div>)
    }
}

export default Counter1